home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Scope / Scope Disk #142 (199x)(Scope PD)(US)[WB].zip / Scope Disk #142 (199x)(Scope PD)(US)[WB].adf / LoadImage / LibStartup.asm < prev    next >
Assembly Source File  |  1990-07-30  |  4KB  |  122 lines

  1. *--------------------------------------------------------------------*
  2. *    Library startup module, not as funky as Jimm's example
  3. *    Aztec code, but (hopefully) okay for Aztec 5.0.
  4. *
  5. *    Note:    Register usage has been rearranged to allow
  6. *        library init call with parameters in registers.
  7. *
  8. *    Based on LibStart.A68 (with some of the bugs taken out),
  9. *    Copyright (C) 1986, 1987 by Manx Software Systems, Inc.
  10. *--------------------------------------------------------------------*
  11.  
  12.     INCLUDE    'exec/types.i'
  13.     INCLUDE    'exec/nodes.i'
  14.     INCLUDE    'exec/resident.i'
  15.  
  16. *--------------------------------------------------------------------*
  17. *    Here we start the code generation.
  18. *--------------------------------------------------------------------*
  19.  
  20.     SECTION    LibCode,CODE
  21.  
  22. *--------------------------------------------------------------------*
  23. *    Not executable (also does long word alignment).
  24. *--------------------------------------------------------------------*
  25.  
  26.     MOVEQ    #-1,D0            ; Fail if run from Shell
  27.     RTS
  28.  
  29. *--------------------------------------------------------------------*
  30. *    Library version, this should match the lib ID string.
  31. *--------------------------------------------------------------------*
  32.  
  33. LIBVERSION    EQU    34
  34.  
  35. *--------------------------------------------------------------------*
  36. *    Global symbols (rather in a bunch than sprenkled).
  37. *--------------------------------------------------------------------*
  38.  
  39.     PUBLIC    _LibRomTag,_LibName,_LibId,_LibInitTab,_LibInit
  40.     PUBLIC    _LibMain,.begin,_geta4,__H0_org
  41.  
  42. *--------------------------------------------------------------------*
  43. *    The RomTag structure, must be in first hunk.
  44. *--------------------------------------------------------------------*
  45.  
  46. _LibRomTag:
  47.  
  48.     DC.W    RTC_MATCHWORD        ; Tag ID (680x0 ILLEGAL)
  49.  
  50.     DC.L    _LibRomTag        ; Points to beginning of tag
  51.     DC.L    _LibEndTag        ; Points to end of tag
  52.  
  53.     DC.B    RTF_AUTOINIT        ; Auto init library
  54.     DC.B    LIBVERSION        ; Library version
  55.     DC.B    NT_LIBRARY        ; This is a library, not a device
  56.     DC.B    0            ; Priority (leave it zero)
  57.  
  58.     DC.L    _LibName        ; Pointer to lib name
  59.     DC.L    _LibId            ; Pointer to lib ID
  60.     DC.L    _LibInitTab        ; Pointer to library init table
  61.  
  62. _LibEndTag:
  63.  
  64. *--------------------------------------------------------------------*
  65. *    This is supposed to be the lib entry point.
  66. *--------------------------------------------------------------------*
  67.  
  68. .begin                    ; First hunk
  69.  
  70. *--------------------------------------------------------------------*
  71. *    Set up the lib environment and call the main init routine.
  72. *
  73. *    Register usage:    D0 - APTR to library base
  74. *            A0 - BPTR to library segment list
  75. *
  76. *    Main init routine is expected to return the library base
  77. *    in D0 if library is ready to be used.
  78. *--------------------------------------------------------------------*
  79.  
  80. _LibInit:
  81.  
  82.     MOVEM.L    D2-D7/A2-A6,-(SP)    ; Save registers
  83.     BSR    _geta4            ; Get A4
  84.     LEA    __H1_end,A1
  85.     LEA    __H2_org,A2
  86.     CMP.L    A1,A2            ; Check if BSS and DATA together
  87.     BNE    Start            ; No, don't have to clear
  88.     MOVE.W    #((__H2_end-__H2_org)/4)-1,D1
  89.     BMI    Start            ; Skip if no bss
  90.  
  91.     MOVEQ    #0,D2
  92. 1$    MOVE.L    D2,(A1)+        ; Clear out memory
  93.     DBRA    D1,1$
  94.  
  95. Start    MOVE.L    A6,_SysBase        ; Put it where we can get it
  96.  
  97.     JSR    _LibMain        ; Call 'C' init routine
  98.  
  99.     MOVEM.L    (SP)+,D2-D7/A2-A6    ; Restore registers
  100.     RTS                ; And return
  101.  
  102. *--------------------------------------------------------------------*
  103. *    Set up A4 to point into the middle of the data segment.
  104. *--------------------------------------------------------------------*
  105.  
  106. _geta4:    FAR    DATA
  107.     LEA    __H1_org+32766,A4
  108.     RTS
  109.  
  110. *--------------------------------------------------------------------*
  111. *    Data segment (globals/hunks).
  112. *--------------------------------------------------------------------*
  113.  
  114.     SECTION    LibData,DATA
  115.  
  116.     PUBLIC    _SysBase,_DOSBase,__H1_org,__H1_end,__H2_org,__H2_end
  117.  
  118.     BSS    _SysBase,4
  119.     BSS    _DOSBase,4
  120.  
  121.     END
  122.